package {{ base_pkg }}.application.{{ entity.domain }};

import {{ base_pkg }}.application.{{ entity.domain }}.dto.{{ entity.name }}DTO;
import {{ base_pkg }}.application.{{ entity.domain }}.converter.{{ entity.name }}DTOConverter;
import {{ base_pkg }}.application.{{ entity.domain }}.validator.{{ entity.name }}Validator;
import {{ base_pkg }}.domain.{{ entity.domain }}.model.aggragate.{{ entity.name }};
import {{ base_pkg }}.domain.{{ entity.domain }}.model.entity.{{ entity.name }}Item;
import {{ base_pkg }}.domain.{{ entity.domain }}.repository.{{ entity.name }}Repository;
import {{ base_pkg }}.domain.{{ entity.domain }}.service.{{ entity.name }}DomainService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service("{{ entity.domain }}UseCase")
public class {{ entity.name }}UseCaseImpl implements {{ entity.name }}UseCase {
    private final {{ entity.name }}DomainService {{ entity.domain }}DomainService;
    private final {{ entity.name }}Repository {{ entity.domain }}Repository;
    private final {{ entity.name }}DTOConverter {{ entity.domain }}DTOConverter;

    @Autowired
    public {{ entity.name }}UseCaseImpl({{ entity.name }}DomainService {{ entity.domain }}DomainService, {{ entity.name }}Repository {{ entity.domain }}Repository, {{ entity.name }}DTOConverter {{ entity.domain }}DTOConverter) {
        this.{{ entity.domain }}DomainService = {{ entity.domain }}DomainService;
        this.{{ entity.domain }}Repository = {{ entity.domain }}Repository;
        this.{{ entity.domain }}DTOConverter = {{ entity.domain }}DTOConverter;
    }

    @Override
    public {{ entity.name }}DTO create({{ entity.name }}DTO dto) {
        {{ entity.name }}Validator.validateForCreate(dto);
        // TODO: 领域服务调用与聚合根创建
        {{ entity.name }} entity = {{ entity.domain }}DomainService.create(dto);
        {{ entity.domain }}Repository.save(entity);
        return {{ entity.domain }}DTOConverter.toDTO(entity);
    }

    @Override
    public List<{{ entity.name }}DTO> list() {
        List<{{ entity.name }}> entities = {{ entity.domain }}Repository.findAll();
        return entities.stream().map({{ entity.domain }}DTOConverter::toDTO).collect(Collectors.toList());
    }
} 